Conversation
Lets MODULE.bazel point starlark_repository at a workspace-local path
instead of an http_archive. Useful when the source already lives on
disk — e.g. a git submodule — and we want to skip the network fetch
entirely. The bcr-frontend project hits this with ~449 overlay-bzl
modules that all derive from the same bazel-central-registry archive;
emitting one `.archive(urls=...)` per module trips GitHub's 429 rate
limit on cold caches.
Changes
- extensions/starlark_repository.bzl: new `local` tag class with attrs
{name, path, build_directives, build_file_generation, languages,
cfgs, imports, imports_out (default "imports.csv"), deleted_files,
reresolve_known_proto_imports, importpath}. The extension impl maps
user-facing `path` to the underlying `local_path` attr and dispatches
to the same starlark_repository repo rule used by `.archive`.
- rules/proto/proto_repository.bzl: in `_proto_repository_impl`'s
local_path branch, resolve workspace-relative paths against the main
workspace root (via Label("@@//:MODULE.bazel").dirname) before
passing them to ctx.watch_tree() and fetch_repo's --path arg. Bare
strings were otherwise interpreted relative to the external repo's
own dir, where the directory doesn't exist.
- rules/proto/proto_repository.bzl: in _generate_proto_repository_info,
return empty string when imports_out is unset, so a future caller
with no imports_out can't trip `exports_files([""])`.
Usage:
starlark_repository = use_extension(
"@build_stack_rules_proto//extensions:starlark_repository.bzl",
"starlark_repository",
)
starlark_repository.local(
name = "bzl.colordiff---1.0.22",
path = "data/bazel-central-registry/modules/colordiff/1.0.22/overlay",
build_directives = ["gazelle:starlarkrepository_root"],
build_file_generation = "clean",
languages = ["starlarkrepository"],
)
use_repo(starlark_repository, "bzl.colordiff---1.0.22")
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Experimental new gazelle extension for collecting the .bzl files of an external resource. Not proto related, it could be upstreamed to gazelle itself if useful.